<!DOCTYPE html>
<html class="x-admin-sm" lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>服务商信息</title>
    <header th:replace="header::html"></header>
</head>
<body>
<div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">首页</a>
            <a href="">雇主管理</a>
            <a>
                <cite>雇主列表</cite></a>
          </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="layui-fluid">
    <div class="layui-row  layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form  layui-col-space5">
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="uname" placeholder="请输入服务商名称" autocomplete="off"
                                   class="layui-input">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn" lay-submit="" lay-filter="search"><i
                                    class="layui-icon">&#xe615;</i></button>
                        </div>
                    </form>
                </div>

                <div class="layui-card-body ">
                    <table class="layui-hide" id="user-name-label" lay-filter="user-name-label"></table>
                </div>

                <div class="layui-card-body ">
                    <script type="text/html" id="barDemo">
                        <a class="layui-btn layui-btn-xs" lay-event="verify"
                        >禁用/启用</a>
                        <a class="layui-btn layui-btn-xs" lay-event="setConsultant"
                        >设置顾问</a>
                        <a class="layui-btn layui-btn-danger  layui-btn-xs" lay-event="cancelConsultant"
                        >取消顾问</a>
                        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="upd"
                        >重置密码</a>
                        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="dlt"
                        >删除用户</a>
                    </script>
                </div>l
            </div>
        </div>
    </div>
</div>
<script>
	layui.use('table', function () {
		var table = layui.table,
			form = layui.form;
		table.render({
			elem: '#user-name-label'
			, url: '/api-back/employer/serviceProvidersList' //数据接口
			, page: true //开启分页
			, response: {
				dataName: 'datas' //规定数据列表的字段名称，默认：data
			}
			, cols: [
				[ //表头
					{title:'序号',type:'numbers'}
					// {type: 'checkbox', fixed: 'left'},
					,{field: 'uid', title: 'ID', align: 'center',style:'display:none;'}
					, {field: 'uaccount', title: '账号',width:'9%'}
					, {field: 'uname', title: '昵称',width:'9%'}
					, {field: 'uphone', title: '联系方式',width:'9%'}
					, {field: 'uscore', title: '信用',align: 'center',sort:true,width:'7%'}
					, {field: 'uaddress', title: '地址',width:'13%'}
					, {field: 'usex', title: '性别',align: 'center',width:'4%'}
					, {field: 'tips1', title: '状态',width:'7%',align: 'center'}
					, {field: 'tips2', title: '类型',width:'8%',align: 'center'}
					, {title: '操作', toolbar: '#barDemo',width:'35%',align: 'center'}
				]
			]
			// done: function () {
			// 	//checkPermission();
			// }

		});
		$('table.layui-table thead tr th:eq(0)').addClass('layui-hide');//隐藏第一列的表头

		//监听工具条
		table.on('tool(user-name-label)', function (obj) {
			var data = obj.data;//获取点击行数据
			if (obj.event === 'upd') {
				layer.confirm('确定重置密码？', function (index) {
					alert(data.uid);
					$.ajax({
						url: "/api-back/employer/resetPass",
						type: "GET",
						data: {uid: data.uid},
						dataType: 'text',
						success: function (msg) {
							if (msg === "yes") {
								layer.alert("重置密码成功", {icon: 1}, function (index1) {
									layer.close(index1);
									table.reload('user-name-label');
									$('table.layui-table thead tr th:eq(0)').addClass('layui-hide');//隐藏第一列的表头
								});

							} else if (msg === "no") {
								layer.alert("重置密码失败", {icon: 1}, function (index1) {
									layer.close(index1);
									table.reload('user-name-label');
									$('table.layui-table thead tr th:eq(0)').addClass('layui-hide');//隐藏第一列的表头
								});

							}
						},
					});

				});
			} else if(obj.event==='verify'){
				var str;
				if (data.pid===3){
					layer.msg('改用户已被删除无法进行该操作！', {icon: 2});
				} else{
					if (data.pid===1) {
						str="确定要禁用该用户？";
					}else{
						str="确定要启用该用户？";
					}

					layer.confirm(str, function (index) {
						$.ajax({
							url: "/api-back/employer/changeS",
							type: "GET",
							data: {uid: data.uid,pid:data.pid},
							dataType: 'text',
							success: function (msg) {
								if (msg === "yes") {
									layer.alert("操作成功", {icon: 1}, function (index1) {
										layer.close(index1);
										table.reload('user-name-label');
										$('table.layui-table thead tr th:eq(0)').addClass('layui-hide');//隐藏第一列的表头
									});

								} else if (msg === "no") {
									layer.alert("操作失败", {icon: 1}, function (index1) {
										layer.close(index1);
										table.reload('user-name-label');
										$('table.layui-table thead tr th:eq(0)').addClass('layui-hide');//隐藏第一列的表头
									});

								}
							}
						});

					});
				}

			}else if(obj.event==='setConsultant'){
				if (data.rid===7){
					layer.msg('该服务商已是顾问，请勿重复操作！', {icon: 2});
                }else{
					layer.confirm('确定设置为顾问？', function (index) {
						$.ajax({
							url: "/api-back/employer/changeServiceType",
							type: "GET",
							data: {uid: data.uid,ak:1},
							dataType: 'text',
							success: function (msg) {
								if (msg === "yes") {
									layer.alert("设置成功", {icon: 1}, function (index1) {
										layer.close(index1);
										table.reload('user-name-label');
										$('table.layui-table thead tr th:eq(0)').addClass('layui-hide');//隐藏第一列的表头
									});

								} else if (msg === "no") {
									layer.alert("信用太低，不符合顾问要求", {icon: 1}, function (index1) {
										layer.close(index1);
										table.reload('user-name-label');
										$('table.layui-table thead tr th:eq(0)').addClass('layui-hide');//隐藏第一列的表头
									});

								}else{
									layer.open({
										type: 2,
										content: "/404.html",
										area: ['60%', '60%'],
										title: '权限不足'
									});
								}
							},
						});

					});
                }


            }else if(obj.event==='cancelConsultant'){
				if (data.rid===3){
					layer.msg('该服务商不是顾问，该操作无效！', {icon: 2});
				}else{
					layer.confirm('确定取消顾问资格？', function (index) {
						$.ajax({
							url: "/api-back/employer/changeServiceType",
							type: "GET",
							data: {uid: data.uid,ak:2},
							dataType: 'text',
							success: function (msg) {
								if (msg === "yes") {
									layer.alert("取消顾问成功", {icon: 1}, function (index1) {
										layer.close(index1);
										table.reload('user-name-label');
										$('table.layui-table thead tr th:eq(0)').addClass('layui-hide');//隐藏第一列的表头
									});

								} else{
									layer.open({
										type: 2,
										content: "/404.html",
										area: ['60%', '60%'],
										title: '权限不足'
									});
								}
							},
						});

					});
                }

            } else{
				if (data.pid===3){
					layer.msg('该用户已被删除请勿重复操作！', {icon: 2});
				} else{
					layer.confirm('确定删除用户？', function (index) {
						var newPid=3;
						alert(data.uid);
						$.ajax({
							url: "/api-back/user/changeS",
							type: "GET",
							data: {uid: data.uid,pid:newPid},
							dataType: 'text',
							success: function (msg) {
								if (msg === "yes") {
									layer.alert("删除用户成功", {icon: 1}, function (index1) {
										layer.close(index1);
										table.reload('user-name-label');
										$('table.layui-table thead tr th:eq(0)').addClass('layui-hide');//隐藏第一列的表头
									});

								} else if (msg === "no") {
									layer.alert("删除用户失败", {icon: 1}, function (index1) {
										layer.close(index1);
										table.reload('user-name-label');
										$('table.layui-table thead tr th:eq(0)').addClass('layui-hide');//隐藏第一列的表头
									});

								}
							},
						});

					});
				}



			}
		});
		//搜索
		form.on('submit(search)', function (data) {
			var uname = data.field.uname;
			table.render({
				elem: '#user-name-label'
				, url: '/api-back/employer/SpecifiedServiceProvidersList' //数据接口
				, page: true //开启分页
				, where: {
					"uname": uname
				}
				, response: {
					countName: 'count', //规定数据总数的字段名称，默认：count
					dataName: 'datas' //规定数据列表的字段名称，默认：data
				}
				, cols: [
					[ //表头
						{title:'序号',type:'numbers'}
						// {type: 'checkbox', fixed: 'left'},
						,{field: 'uid', title: 'ID', align: 'center',style:'display:none;'}
						, {field: 'uaccount', title: '账号',width:'9%'}
						, {field: 'uname', title: '昵称',width:'9%'}
						, {field: 'uphone', title: '联系方式',width:'9%'}
						, {field: 'uscore', title: '信用',align: 'center',sort:true,width:'7%'}
						, {field: 'uaddress', title: '地址',width:'13%'}
						, {field: 'usex', title: '性别',align: 'center',width:'4%'}
						, {field: 'tips1', title: '状态',width:'7%',align: 'center'}
						, {field: 'tips2', title: '类型',width:'8%',align: 'center'}
						, {title: '操作', toolbar: '#barDemo',width:'35%',align: 'center'}
					]
				]
			});
			$('table.layui-table thead tr th:eq(0)').addClass('layui-hide');
			return false;
		});



	});

</script>


</body>
</html>